package com.ruoyi.customer.controller;

import com.ruoyi.common.core.constant.HttpStatus;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.customer.domain.CustomerTag;
import com.ruoyi.customer.service.ICustomerTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tag")
public class CustomerTagController extends BaseController {
    @Autowired
    private ICustomerTagService tagService;

    /**
     * 查询顾客标签列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CustomerTag tag) {
        startPage();
        List<CustomerTag> list = tagService.selectCustomerTagList(tag);
        return getDataTable(list);
    }

    /**
     * 获取顾客标签详细信息
     */
    @GetMapping(value = "/{tagId}")
    public AjaxResult getInfo(@PathVariable("tagId") Long tagId) {
        return AjaxResult.success(tagService.selectCustomerTagById(tagId));
    }

    /**
     * 新增顾客标签
     */
    @PostMapping
    public AjaxResult add(@RequestBody CustomerTag tag) {
        if (tagService.insertCustomerTag(tag) > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error(HttpStatus.ERROR, "新增顾客标签失败");
    }

    /**
     * 修改顾客标签
     */
    @PutMapping
    public AjaxResult edit(@RequestBody CustomerTag tag) {
        if (tagService.updateCustomerTag(tag) > 0) {
            return AjaxResult.success();
        }
        return AjaxResult.error(HttpStatus.ERROR, "修改顾客标签失败");
    }

    /**
     * 删除顾客标签
     */
    @DeleteMapping("/{tagIds}")
    public AjaxResult remove(@PathVariable Long[] tagIds) {
        return toAjax(tagService.deleteCustomerTagByIds(tagIds));
    }
}
